<template>
  <div class="opinionAudit">
    <div class="clearfloat">
      <orderStatistics :myInfo ='myInfo'  @getData='getTableData'/>
      <!-- 列表查找 -->
      <div class="search-wrap fr">
        <table-search
          ref="table-search"
          :selectHead="selectHead"
          @searchMethods="searchMethods">
        </table-search>
      </div>
    </div>


    <el-table
      ref="tableRef"
      :data="tableData"
      border
      style="width: 100%"
      v-loading="loading"
      @sort-change='tableSortChange'
      height="88%">
      <el-table-column show-overflow-tooltip label="ID" width="60" align="left">
        <template slot-scope="scope">{{(scope.$index+1)+(currentPage-1)*pageSize }}</template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="反馈人姓名" align="left" prop='user_name' sortable='custom' min-width="150">
        <template slot-scope="scope">
          {{ scope.row.users.name }}
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="反馈人类型" align="left" prop='user_type' sortable='custom' min-width="150">
        <template slot-scope="scope">
          {{ scope.row.users.role_id | opinionsUserType }}
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="意见类型" align="left" prop='type' sortable='custom' min-width="150">
        <template slot-scope="scope">
          {{ scope.row.type | opinionType }}
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="处理进度" align="left" prop='status' sortable='custom' min-width="150">
        <template slot-scope="scope">
          {{ scope.row.status | opinionStatus }}
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="意见内容" align="left" prop='opinions' sortable='custom' min-width="150"></el-table-column>
      <el-table-column show-overflow-tooltip label="提交时间" align="left" prop='created_at' sortable='custom' min-width="150"></el-table-column>
      <el-table-column show-overflow-tooltip label="处理时间" align="left" prop='adopt_time' sortable='custom' min-width="150"></el-table-column>

      <el-table-column
        align="center"
        fixed="right"
        label="操作"
        width="140">
        <template slot-scope="scope">
          <el-button @click="reviews(scope.row)" type="primary" size="small" :disabled="scope.row.status != 0">审核</el-button>
          <!-- <el-button @click="reviews(scope.row,'yes')" type="success" size="small">通过</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination @paginationChange="paginateChange" :total="total"></pagination>
    <opinionsReview ref="opinionsReview" @refresh ='getTableData'/>
  </div>
</template>

<script>
import orderStatistics from "~/components/orderStatistics"
import { getMyInfo } from "~/api/user"
import Pagination from '~/components/pagination'
import tableSearch from '~/components/tableSearch'
import opinionsReview from './components/opinionReview-dialog'
export default {
  data () {
    return {
      baseUrl: global.baseurl,
      tableData: [],
      loading: false,
      pageSize: 25, //一页可以几条
      currentPage: 1, //目前在第几页
      total: 0,
      paramsByOpinion: {

      },
      myInfo: {
        opinion_collect_audit : 0
      },
      selectHead: [
        {
          label: '反馈人姓名',
          props: 'user_name'
        },
        {
          label: '反馈人类型',
          props: 'user_type'
        },
        {
          label: '意见类型',
          props: 'type'
        },
        {
          label: '处理进度',
          props: 'status'
        },
        {
          label: '意见内容',
          props: 'opinions'
        },
        {
          label: '提交时间',
          props: 'time'
        },
        {
          label: '处理时间',
          props: 'adoptTime'
        },
      ],
      search_params: {},
    }
  },
  components: {
    Pagination,
    tableSearch,
    orderStatistics,
    opinionsReview
  },
  created () {
    this.getTableData()
  },
  methods: {
    async getMyinfo (params) {
      let myInfo = await getMyInfo(this.$axios, params);
      if (myInfo.data.status == 'success') {
        this.$store.commit("setRoleInfo",myInfo.data.data)
        this.$store.commit("setUser",myInfo.data.data)
        this.myInfo = myInfo.data.data
        this.roleID = this.myInfo.role_id
      }
    },
    getTableData (args) {
      let params = {
        perPage: this.pageSize,
        page: this.currentPage,
      }
      params = {...params, ...this.paramsByOpinion, ...this.search_params}
      if (args) {
        params = {...params, ...args}
      }
      this.$axios.get('api/opinion_collection', {
        params: params
      }).then(res => {
        if (res.data.code == 200) {
          this.loading = false
          this.tableData = res.data.data
          this.pageSize = res.data.page.per_page
          this.total = res.data.page.total
           // 重绘表格解决错位问题
          this.$nextTick(()=>{
            this.$refs.tableRef.doLayout()
          })
          this.getMyinfo()
        } else {
          this.$message.error('服务器繁忙')
        }
      })
    },

    searchMethods(params, no_search) {
      // this.sort_params = {}
      this.currentPage = 1
      this.pageSize = 25
      this.search_params = params
      if (params.time) {
        this.search_params.start_time = params.time[0]
        this.search_params.end_time = params.time[1]
        delete this.search_params.time
      }
      if (params.adoptTime) {
        this.search_params.adopt_start_time = params.adoptTime[0]
        this.search_params.adopt_end_time = params.adoptTime[1]
        delete this.search_params.adoptTime
      }
      if (!no_search) {
          this.getTableData()
      }
    },
    paginateChange(params) {
      this.pageSize = params.perPage
      this.currentPage = params.page
      this.getTableData()
    },
    tableSortChange (column) {
      if (column.order === 'descending') {
        this.paramsByOpinion.sort_str = column.prop
        this.paramsByOpinion.sort_order = 'desc'
      } else if (column.order === 'ascending'){
        this.paramsByOpinion.sort_str = column.prop
        this.paramsByOpinion.sort_order = 'asc'
      } else {
        delete this.paramsByOpinion.sort_str
        delete this.paramsByOpinion.sort_order
      }
      this.loading = true
      this.currentPage = 1
      this.getTableData()
    },
    reviews(data) {
      this.$refs['opinionsReview'].show(data)
    },

  }
}
</script>

<style lang='less' type='text/css' scoped>
  .opinionAudit {
    height: 100%; //撑满表格
    .withdraw-header {
      margin-bottom: 20px;
    }
    .el-table {
      width: 99.9% !important;

      .el-table__body {
        .pay-status {
          padding: 0;
          .cell {
            display: flex;
            align-items: center;
            justify-content: center;
            .el-image {
              width: 40px;
              height: 40px;
              margin-left: 10px;
              &:nth-last-child(1) {
                margin-left: 0;
              }
              image {
                width: 100%;
                height: 100%;
                display: block;
              }
            }
          }
        }
      }
    }

  }
</style>
